package com.example.demo.controller;

import com.example.demo.dao.UserRepository;
import com.example.demo.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserRepository userRepository;
    @PostMapping("/save-user")
    public User saveUser(User user){
        System.out.println(user.getUsername()+"   "+user.getPassword());
      user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword()));
      return userRepository.save(user);
    }

    @GetMapping("/list-user")
    public String listUser(String username){
        return "hhhhhh";
    //  return userRepository.findByUsername("root");
    }

    @GetMapping("/eeee/list-user")
    public String fun(String username){
        return "hhhhhh";
        //  return userRepository.findByUsername("root");
    }
//    @GetMapping("/hello")
//    public String hello(String username){
//     //  User user =  userRepository.findByUsername(username);
//     //  System.out.println(user);
//        return "hello ";
//    }
}
